<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: class.product.php 542 2015-02-28 11:59:22Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 542 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2015-02-28 11:59:22 +0000 (Sat, 28 Feb 2015) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

class product {
	function __construct($pID = 0) {
		global $db;

		$this->pID = $pID;
		$this->useStandardImage = true;
		$this->standardImage = 'no_img_';
		if($pID == 0) {
			$this->isProduct = false;
			return;
		}

		$product = $db->db_query("
			SELECT
				ifnull(p2m.products_id, p.products_id) products_id_base, p.*, pd.*
			FROM
				".TABLE_PRODUCTS." AS p
				left join ".TABLE_PRODUCTS_DESCRIPTION." AS pd on p.products_id = pd.products_id
				left join ".TABLE_PRODUCTS_TO_MODELS." p2m on p.products_id = p2m.products_model
			where
				p.products_id = '".$this->pID."'
				and p.products_status >= 1 
				and pd.language_id = '".(int)$_SESSION['languages_id']."'
			".$this->groupCheck().$this->fsk18(), true);

		//echo_e($product->sql, 'e');
		if($product->_numOfRows) {
			$this->isProduct = true;
			$this->data = $product->fields;

			// Template Massenware
			$this->data['product_template_plain'] = 'product_bulk.html';
			/* statisch --
			$rec = $db->db_query("
				select 
					p.product_template
				from
					".TABLE_PRODUCTS_TO_CATEGORIES." p2c
					inner join ".TABLE_PRODUCTS_TO_CATEGORIES." p2c2 on p2c.categories_id = p2c2.categories_id
					inner join ".TABLE_PRODUCTS." p on p2c2.products_id = p.products_id
				where
					p2c.products_id = '".$this->pID."'
					and p.products_status = 2
				limit 1", true);

			if($rec->_numOfRows)
				$this->data['product_template_plain'] = $rec->fields['product_template'];
			*/
			
		} else
			$this->isProduct = false;
	}

	/**
	 * Liefert das SQL Statement für FSK 18 Produkte
	 * @author siekiera
	 * @return sql
	 */

	function fsk18() {
		if($_SESSION['customers_status']['customers_fsk18_display'] == '0')
			return $fsk_lock = ' AND p.products_fsk18 != 1';
	}

	/**
	 * Liefert das SQL Statement für den GruppenCheck
	 * @author siekiera
	 * @return sql
	 */

	function groupCheck() {
		if(GROUP_CHECK == 'true')
			return " AND p.group_permission_".$_SESSION['customers_status']['customers_status_id']." = 1 ";
	}

	/**
	 Query for tag cloud
	 **/
	function getTagCloud() {
		global $db;

		$products_tags = $db->db_query("SELECT
											tag
										FROM
											".TABLE_TAG_TO_PRODUCT."
										WHERE
											pID='".$this->pID."'
										AND
											lID = '".(int)$_SESSION['languages_id']."'
										ORDER BY
											tag ASC", true);

		if($products_tags->_numOfRows > 0){
			while(!$products_tags->EOF){
				if(MODULE_SEO_URL_INDEX_STATUS == 'True')
					$link = href_link('tag/'.urlencode($products_tags->fields['tag']).'/');
				else
					$link = href_link('taglisting.php', 'tag='. urlencode($products_tags->fields['tag']));
				
				$tags[] = array('tagcloud' => '<a class="product_info_tag" href="'.$link.'">'.$products_tags->fields['tag'].'</a>');
				$products_tags->MoveNext();
			}
			return $tags;
		} else
			return;
	}

	/**
	 Query for attributes count
	 **/
	function getAttributesCount() {
		global $db;

		$products_attributes = $db->db_query("SELECT
													products_options_id
												FROM
													".TABLE_PRODUCTS_OPTIONS." popt,
													".TABLE_PRODUCTS_ATTRIBUTES." patrib
												WHERE
													patrib.products_id = '".$this->pID."'
												AND
													patrib.options_id = popt.products_options_id
												AND
													popt.language_id = '".(int) $_SESSION['languages_id']."'", true);

		return $products_attributes->_numOfRows;
	}

	/**
	 Query for reviews count
	 **/
	function getReviewsCount() {
		global $db;

		$reviews = $db->db_query("SELECT
										COUNT(*) AS total
									FROM
										".TABLE_REVIEWS." r,
										".TABLE_REVIEWS_DESCRIPTION." rd
									WHERE
										r.products_id = '".$this->pID."'
									AND
										r.reviews_status = '1'
									AND
										r.reviews_id = rd.reviews_id
									AND
										rd.languages_id = '".$_SESSION['languages_id']."'
									AND
										rd.reviews_text !=''");
		return $reviews->fields['total'];
	}

	/**
	 Select reviews
	 **/
	function getReviews() {
		global $db;

		$data_reviews = array ();
		$reviews = $db->db_query("SELECT
									r.reviews_rating,
									r.reviews_id,
									r.customers_name,
									r.date_added,
									r.last_modified,
									r.reviews_read,
									rd.reviews_text
								FROM
									".TABLE_REVIEWS." r,
									".TABLE_REVIEWS_DESCRIPTION." rd
								WHERE
									r.products_id = '".$this->pID."'
								AND
									r.reviews_id = rd.reviews_id
								AND
									r.reviews_status = '1'
								AND
									rd.languages_id = '".$_SESSION['languages_id']."'
								ORDER BY
									reviews_id DESC");
									
		if($reviews->_numOfRows) {
			$row = 0;
			$data_reviews = array ();
			while(!$reviews->EOF) {
				$row ++;
				
				if(MODULE_SEO_URL_INDEX_STATUS == 'True')
					$link = 'review-'.$reviews->fields['reviews_id'].'/'.get_url_friendly_text(get_products_name($this->pID)).'.html';
				else
					$link = href_link(FILENAME_PRODUCT_REVIEWS_INFO, 'reviews_id='.$reviews->fields['reviews_id']);
					
				$text = substr($reviews->fields['reviews_text'], 0 , 299).' ... <a href="'.$link.'">[mehr]</a>';
				
				$data_reviews[] = array('AUTHOR' => $reviews->fields['customers_name'],
										'DATE' => date_short($reviews->fields['date_added']),
										'RATING' => image('templates/'.CURRENT_TEMPLATE.'/img/stars_'.$reviews->fields['reviews_rating'].'.png', sprintf(TEXT_OF_5_STARS, $reviews->fields['reviews_rating'])),
										'TEXT' => break_string($reviews->fields['reviews_text'], 125, '<br />'));
				if($row == PRODUCT_REVIEWS_VIEW)
					break;
				$reviews->MoveNext();
			}
		}
		return $data_reviews;
	}

	/**
	 return model if set, else return name
	 **/
	function getBreadcrumbModel() {
		if ($this->data['products_name'] != "")
			return $this->data['products_name'];
		return $this->data['products_model'];
	}

	/**
	 Also purchased products related to current
	 **/
	function getAlsoPurchased($list_data) {
		global $price, $db;

		$module_content = array ();

		$orders = $db->db_query_limit("SELECT
											p.products_fsk18,
											p.products_id,
											p.products_quantity,
											p.products_price,
											p.products_tax_class_id,
											p.products_list_overlay,
											p.products_image,
											pd.products_img_alt,
											pd.products_name,
											p.products_vpe,
											p.products_vpe_status,
											p.products_vpe_value,
											pd.products_short_description
										FROM
											".TABLE_ORDERS_PRODUCTS." opa, ".TABLE_ORDERS_PRODUCTS." opb, ".TABLE_ORDERS." o, ".TABLE_PRODUCTS." p, ".TABLE_PRODUCTS_DESCRIPTION." pd
										WHERE
											opa.products_id = '".$this->pID."'
										AND
											opa.orders_id = opb.orders_id
										AND
											opb.products_id != '".$this->pID."'
										AND
											opb.products_id = p.products_id
										AND
											opb.orders_id = o.orders_id
										AND
											p.products_status = '1'
										AND
											pd.language_id = '".(int) $_SESSION['languages_id']."'
										AND
											opb.products_id = pd.products_id
											".$this->groupCheck().$this->fsk18()."
										GROUP BY
											p.products_id
										ORDER BY
											o.date_purchased DESC", MAX_DISPLAY_ALSO_PURCHASED, true);
		$row=0;
		while(!$orders->EOF) { $row++;
			$module_content[] = $this->buildDataArray($orders->fields, 'thumbnail', $list_data, $row);
			$orders->MoveNext();
		}
		return $module_content;
	}

	/**
	  Cross selling
	 **/
	function getCrossSells() {
		global $db;

		$cross_sells = $db->db_query("SELECT products_xsell_grp_name_id FROM ".TABLE_PRODUCTS_XSELL." WHERE products_id = '".$this->pID."' GROUP BY products_xsell_grp_name_id", true);

		$cross_sell_data = array ();
		if($cross_sells->_numOfRows) {
			$list_data = get_list_data('cross_selling');
			while(!$cross_sells->EOF) {
				$xsell = $db->db_query("SELECT
											p.products_fsk18,
											p.products_tax_class_id,
											p.products_id,
											p.products_quantity,
											p.products_image,
											p.products_list_overlay,
											pd.products_img_alt,
											pd.products_name,
											pd.products_short_description,
											p.products_fsk18,p.products_price,p.products_vpe,
											p.products_vpe_status,
											p.products_vpe_value,
											xp.sort_order
										FROM
											".TABLE_PRODUCTS_XSELL." xp, ".TABLE_PRODUCTS." p, ".TABLE_PRODUCTS_DESCRIPTION." pd
										WHERE
											xp.products_id = '".$this->pID."'
										AND
											xp.xsell_id = p.products_id
											".$this->groupCheck().$this->fsk18()."
										AND
											p.products_id = pd.products_id
										AND
											xp.products_xsell_grp_name_id='".$cross_sells->fields['products_xsell_grp_name_id']."'
										AND
											pd.language_id = '".$_SESSION['languages_id']."'
										AND
											p.products_status = '1'
										ORDER BY
											xp.sort_order ASC", true);

				if($xsell->_numOfRows > 0)
					$cross_sell_data[$cross_sells->fields['products_xsell_grp_name_id']] = array('GROUP' => get_cross_sell_name($cross_sells->fields['products_xsell_grp_name_id']),
																								'PRODUCTS' => array ());

				$row = 0;
				while(!$xsell->EOF) { $row++;
					$cross_sell_data[$cross_sells->fields['products_xsell_grp_name_id']]['PRODUCTS'][] = $this->buildDataArray($xsell->fields, 'thumbnail', $list_data, $row);
					$xsell->MoveNext();
				}
				$cross_sells->MoveNext();
			}
			return $cross_sell_data;
		}
	}

	/**
	 Reverse cross sells
	 **/
	 function getReverseCrossSells() {
	 	global $db;
		$list_data = get_list_data('reverse_cross_selling');
		$xsell = $db->db_query("SELECT
									p.products_tax_class_id,
									p.products_id,
									p.products_quantity,
									p.products_image,
									pd.products_img_alt,
									pd.products_name,
									pd.products_short_description,
									p.products_fsk18,
									p.products_price,
									p.products_list_overlay,
									p.products_vpe,
									p.products_vpe_status,
									p.products_vpe_value,
                            		xp.sort_order
                            	FROM
                            		".TABLE_PRODUCTS_XSELL." xp,
                            		".TABLE_PRODUCTS." p,
                            		".TABLE_PRODUCTS_DESCRIPTION." pd
                           		WHERE
                           			xp.xsell_id = '".$this->pID."'
                           		AND
                           			xp.products_id = p.products_id
                           			".$this->groupCheck().$this->fsk18()."
                           		AND
                           			p.products_id = pd.products_id
                           		AND
                           			pd.language_id = '".$_SESSION['languages_id']."'
                           		AND
                           			p.products_status = '1'
                           		ORDER BY
                           			xp.sort_order ASC", true);
		$i = 0;
		while(!$xsell->EOF) { $i++;
			$cross_sell_data[] = $this->buildDataArray($xsell->fields, 'thumbnail', $list_data, $i);
			$xsell->MoveNext();
		}
		return $cross_sell_data;
	}

	/**
	 Zuletzt angesehen
	**/
	function getLastViewed() {
		global $db;

		if(MAX_DISPLAY_LAST_VIEWED != 0) {
			if(isset($_SESSION['tracking']['products_history'][0])) {
				$product_ids = array_reverse($_SESSION['tracking']['products_history']);
				$row = 0;
				for($i = 0; $i < sizeof($product_ids); $i++) {
					if($product_ids[$i] != $this->pID) {
						$row++;
						$last_viewed = $db->db_query("SELECT
															p.products_id,
															p.products_tax_class_id,
															p.products_quantity,
															p.products_image,
															pd.products_img_alt,
															pd.products_name,
															pd.products_description,
															pd.products_short_description,
															p.products_price,
															p.products_list_overlay,
															p.products_vpe,
															p.products_vpe_status,
															p.products_vpe_value
														FROM
															".TABLE_PRODUCTS." AS p
														JOIN
															 ".TABLE_PRODUCTS_DESCRIPTION." AS pd ON (pd.language_id = '".$_SESSION['languages_id']."')
														AND
															p.products_status = '1'
														AND
															 pd.products_id = '".(int)$product_ids[$i]."'
														AND
															p.products_id = '".(int)$product_ids[$i]."'", true);

						$last_viewed_data[] = $this->buildDataArray($last_viewed->fields, 'thumbnail', 'last_viewed_detail', $row);
						if($row == MAX_DISPLAY_LAST_VIEWED)
							break;
					}
				}
				if(is_array($last_viewed_data))
					return $last_viewed_data;
			}
		}
	}


	/**
		Staffelpreise
	**/
	function getGraduated() {
		global $price, $db;
		$special_percent = '';
		
		$check = $price->CheckSpecial($this->pID);
		if(!empty($check))	
			$special_percent = (100 - ($check / $price->getPprice($this->pID)) * 100);
		
		if($_SESSION['customers_status']['customers_status_id'] == '0')
			$gruppe = '1';
		else
			$gruppe = (int)$_SESSION['customers_status']['customers_status_id'];

		$staffels = $db->db_query("SELECT
										quantity,
										personal_offer
									FROM
										".TABLE_PERSONAL_OFFERS_BY.$gruppe."
									WHERE
										products_id = '".$this->pID."'
									ORDER BY
										quantity ASC", true);

		$discount = $price->CheckDiscount($this->pID);
		$staffel = array();

		while(!$staffels->EOF) {
			$staffel[] = array('stk' => $staffels->fields['quantity'], 
								'price' => $staffels->fields['personal_offer']);
			$staffels->MoveNext();
		}
		$staffel_data = array();

		for ($i = 0, $n = sizeof($staffel); $i < $n; $i ++) {
			if ($staffel[$i]['stk'] == 1) {
				$quantity = $staffel[$i]['stk'];
				if ($staffel[$i+1]['stk'] !='')
					$quantity = $staffel[$i]['stk'].' - '. ($staffel[$i +1]['stk'] - 1);
			} else {
				$quantity = ' > '.($staffel[$i]['stk']-1);
				if ($staffel[$i+1]['stk'] !='')
					$quantity = $staffel[$i]['stk'].' - '. ($staffel[$i +1]['stk'] - 1);
			}
			$vpe = '';
			if ($this->data['products_vpe_status'] == 1 && $this->data['products_vpe_value'] != 0.0 && $staffel[$i]['price'] > 0) {
				$vpe = $staffel[$i]['price'] - $staffel[$i]['price'] / 100 * $discount;
				$vpe = $vpe * (1 / $this->data['products_vpe_value']);
				$vpe = ' ('.$price->format($vpe, true, $this->data['products_tax_class_id']).TXT_PER.get_vpe_name($this->data['products_vpe']).')';
			}
			
			$rabatt = ($staffel[$i]['price'] - $staffel[$i]['price'] / 100 * $discount);
			
			if(!empty($special_percent)){
				$special = (( $rabatt / 100 ) * (100-$special_percent));
				$product_price = '<span class="product_info_new">'.$price->format($special, true, $this->data['products_tax_class_id']).'</span> <span class="product_info_old">'.INSTEAD.' '.$price->format($rabatt, true, $this->data['products_tax_class_id']).'</span>';
			} else 
				$product_price = $price->format($rabatt, true, $this->data['products_tax_class_id']);		
			
			$staffel_data[$i] = array(	'QUANTITY' => $quantity,
										'VPE' => $vpe,
										'PRICE' => $product_price);
		}
		return $staffel_data;
	}

	/**
	  valid flag
	 **/
	function isProduct() {
		return $this->isProduct;
	}

	function getBuyNowButton($id, $name) {
		global $PHP_SELF, $current_category_id;
		
		if(MODULE_SEO_URL_INDEX_STATUS == 'True')
			$url = href_link(FILENAME_DEFAULT, 'cPath='.$current_category_id).'buy/'.$id.'/'.get_url_friendly_text($name).'.html';
		else
			$url = href_link($PHP_SELF, 'action=buy_now&products_id='.$id.'&'.get_all_get_params(array ('action', 'cat', 'coID', 'per_site', 'view_as', 'filter_id', 'multisort', 'tag', 'keywords', 'maxp', 'minp', 'filter', 'sub_filter')), 'NONSSL');

		return '<a class="no_target buy_product" title="'.TEXT_BUY.$name.TEXT_NOW.'" href="'.$url.'">'.image_button('button_buy_now.gif',((CSS_BUTTON_ACTIVE=='true'||CSS_BUTTON_ACTIVE=='text')?TEXT_BUTTON_BUY_NOW:TEXT_BUY.$name.TEXT_NOW)).'</a>';
	}

	function getWishlistButton($id, $name) {
		global $PHP_SELF, $current_category_id;
		
		if(MODULE_SEO_URL_INDEX_STATUS == 'True')
			$url = href_link(FILENAME_DEFAULT, 'cPath='.$current_category_id).'wishlist/'.$id.'/'.get_url_friendly_text($name).'.html';
		else
			$url = href_link($PHP_SELF, 'action=wishlist&products_id='.$id.'&'.get_all_get_params(array ('action', 'coID', 'per_site', 'view_as', 'filter_id', 'multisort', 'tag', 'keywords', 'maxp', 'minp', 'filter', 'sub_filter')), 'NONSSL');

		return '<a title="'.$name.TEXT_NOW_TO_WISHLIST.'" href="'.$url.'">'.image_button('button_to_wish_list.gif',((CSS_BUTTON_ACTIVE=='true'||CSS_BUTTON_ACTIVE=='text')?TEXT_TO_WISHLIST:$name.TEXT_NOW_TO_WISHLIST)).'</a>';
	}

	function getVPEtext($product, $product_price) {
		global $price;

		require_once(DIR_FS_INC.'inc.get_vpe_name.php');

		if(!is_array($product))
			$product = $this->data;

		if($product['products_vpe_value'] != '0.0000' && $product['products_vpe_status'] == 1)
			return $price->format($product_price * (1 / $product['products_vpe_value']), true).TXT_PER.get_vpe_name($product['products_vpe']);
		else
			return $price->format($product_price, true).TXT_PER.get_vpe_name($product['products_vpe']);
			
		return;
	}

	function getStockImg($qty) {
		if($qty >= STOCK_WARNING_GREEN)
			$img = '<img class="product_stock_img" '.get_img_size('images/icons/ampel_gruen.png').' src="'.DIR_WS_CATALOG.'images/icons/ampel_gruen.png" alt="'.$qty.'" title="'.$qty.'" />';
		elseif(($qty > STOCK_WARNING_RED && $qty < STOCK_WARNING_GREEN) || $qty == STOCK_WARNING_YELLOW)
			$img = '<img class="product_stock_img" '.get_img_size('images/icons/ampel_gruen.png').' src="'.DIR_WS_CATALOG.'images/icons/ampel_gelb.png" alt="'.$qty.'" title="'.$qty.'" />';
		elseif($qty <= STOCK_WARNING_RED)
			$img = '<img class="product_stock_img" '.get_img_size('images/icons/ampel_gruen.png').' src="'.DIR_WS_CATALOG.'images/icons/ampel_rot.png" alt="'.$qty.'" title="'.$qty.'" />';
		else
			$img = '';

		return $img;
	}

	function buildDataArray($array, $image = 'thumbnail', $site_params, $count = '1', $max_img_size = '') {
		global $price, $main, $db, $listing;

		switch($site_params['col']) {
			case 0:
				$col_class = 'col_0';
				break;
			case 2:
				$col_class = 'col_2';
				break;
			case 3:
				$col_class = 'col_3';
				break;
			case 4:
				$col_class = 'col_4';
				break;
			default:
				$col_class = 'col_1';
				break;
		}

		if(!empty($site_params['col']) && is_numeric($site_params['col'])) {
			if((int)$count % $site_params['col'] == 0) $col_class .= ' last_li';
			else $col_class .= '';
		}
				
		if((int)$site_params['col'] == 1) $col_class .= ' only_one';
		else $col_class .= ' gallery_item';

		$tax_rate = $price->TAX[$array['products_tax_class_id']];

		if((int)$site_params['p_price'] == 1) {
			$products_price_raw = $price->GetPrice($array['products_id'], true, 1, $array['products_tax_class_id'], $array['products_price'], 1, $site_params['list_type']);
			if(PRICE_AS_IMAGE == 'true')
				$product_price = $products_price_raw;
			else
				$product_price = $products_price_raw['formated'];
 		}

		if (method_exists($price, 'CheckSpecialProduktGroup')) {
			$specialPriceArr = $price->CheckSpecialProduktGroup($array['products_id']);
			if(!empty($specialPriceArr)) {
				$col_class .= ' special_product';
				$gespart = $specialPriceArr['discount']['percent'] * 100.0;
				$extra_div = '<a href="'.href_link(FILENAME_PRODUCT_INFO, 'products_id='.$array['products_id']).'" title="'.SPECIALS_PRICE.'" class="specials_badget"><span>'.sprintf(SPECIALS_GADGET, round($gespart)).'</span></a>';
			}
		}
 		else if(check_for_special($array['products_id']) && $listing->listName !='mosaic') {
			$col_class .= ' special_product';
			$gespart = ($array['products_price'] - $price->CheckSpecial($array['products_id'])) / $array['products_price'] * 100;
			$extra_div = '<a href="'.href_link(FILENAME_PRODUCT_INFO, 'products_id='.$array['products_id']).'" title="'.SPECIALS_PRICE.'" class="specials_badget"><span>'.sprintf(SPECIALS_GADGET, round($gespart)).'</span></a>';
		}
 		
		if($_SESSION['customers_status']['customers_status_show_price'] != '0') {
			if($_SESSION['customers_status']['customers_fsk18'] == '1') {
				if($array['products_fsk18'] == '0') {
					$buy_now = $this->getBuyNowButton($array['products_id'], $array['products_name'], $site);
					$wishlist = $this->getWishlistButton($array['products_id'], $array['products_name']);
				}
			} else {
				$buy_now = $this->getBuyNowButton($array['products_id'], $array['products_name'], $site);
				$wishlist = $this->getWishlistButton($array['products_id'], $array['products_name']);
			}
		}
		
		if($_SESSION['customers_status']['customers_status_id'] == 0) {
			$extra_div .= '<div class="admin_listing_panel">
							<a title="'.$array['products_name'].' - in neuem Tab bearbeiten" target="_blank" href="'.href_link_admin(FILENAME_EDIT_PRODUCTS, 'cPath='.get_product_path($array['products_id']).'&pID='.$array['products_id'].'&'.$this->getMenuID('categories')).'&action=new_product">
								<img style="display:none" src="/images/icons/folder--pencil.png" alt="'.$array['products_name'].' bearbeiten" />
							</a>
						</div>';
		}
		
		$shipping_status_name = $main->getShippingStatusName($array['products_shippingtime']);
		$shipping_status_image = $main->getShippingStatusImage($array['products_shippingtime']);
		
		if(PRODUCT_LISTING_MANU_IMG == 'true' && ($site_params['p_manu_img'] == 1) && !empty($array['brand_id'])) {
			$brand = get_brand_data($array['brand_id']);

			if(!empty($brand['image']))
				$brand_image = $brand['image'];
		}

		if(PRODUCT_LISTING_MANU_NAME == 'true' && ($site_params['p_manu_name'] == 1)) {
			$brand = get_brand_data($array['brand_id']);
			
			if(!empty($brand['url']))
				$brand_url = href_link(FILENAME_REDIRECT,'action=brand&brand='.$brand['id']);
			if(!empty($brand['desc']))
				$brand_desc = $brand['desc'];
			if(!empty($brand['name']))
				$brand_name = $brand['name'];
		}

		if($site_params['p_reviews'] == 1) {
			$reviews = $db->db_query("SELECT reviews_id, COUNT(reviews_rating) AS anzahl, reviews_rating FROM ".TABLE_REVIEWS." WHERE products_id = '".$array['products_id']."' AND reviews_status = '1' GROUP BY products_id ORDER BY reviews_rating DESC");
			$reviews_anzahl = $reviews->_numOfRows;

			if($reviews_anzahl > 0) {	
				require(DIR_FS_INC.'inc.get_review_score.php');
				$score = get_review_score($array['products_id'], $reviews->fields['anzahl']);
				
				$reviews_img = '<span class="product_listing_review_count">
									<img height="13" width="68" src="templates/'.CURRENT_TEMPLATE.'/img/stars_'.$score.'.png" alt="'.$reviews->fields['anzahl'].' '.TEXT_PRODUCTS_REVIEWS.'" title="'.$reviews->fields['anzahl'].' '.TEXT_PRODUCTS_REVIEWS.'" /> <span>'.$score.'/<b>5</b></span>
								</span>';
			}
		}
		
		if(PRODUCT_LISTING_VPE == 'true' && ($site_params['p_vpe'] == 1) && $array['products_vpe_value'] !='0.0000' && $array['products_vpe_status'] == '1')
			$vpe = $this->getVPEtext($array, $products_price_raw['plain']);
		
		if(PRODUCT_LISTING_MODEL == 'true' && ($site_params['p_model'] == 1))
			$model = $array['products_model'];
		
		if($site_params['p_isbn'] == 1)
			$isbn = $array['products_isbn'];
		
		if($site_params['p_stockimg'] == 1)
			$stock_img = $this->getStockImg($array['products_quantity']);

		if($site_params['b_details'] == 1)
			$button_details = '<a title="'.$array['products_name'].'" href="'.href_link(FILENAME_PRODUCT_INFO, product_link($array['products_id'], $array['products_name'])).'">'.image_button('button_details.gif', 'Details').'</a>';

		if($site_params['p_short_desc'] == 1)
			$description = truncate(strip_tags($array['products_short_description']), $site_params['p_short_desc_lenght']);
		elseif($site_params['p_long_desc'] == 1)
			$description = truncate($array['products_description'], $site_params['p_long_desc_lenght']);
		else
			$description = '';

		if($site_params['p_img'] == 1)
			if($array['products_fsk18'] == 1) {
				$usk_img = $db->db_query("SELECT products_usk FROM ".TABLE_PRODUCTS." WHERE products_id = '".$array['products_id']."'");
				$img = DIR_WS_ICONS.'usk/usk_icon_'.$usk_img->fields['products_usk'].'.png';
				$img_tile = DIR_WS_ICONS.'usk/usk_icon_'.$usk_img->fields['products_usk'].'.png';
			} 
			else {
				$img = $this->productImage($array['products_image'], $image);
				$img_tile = $this->productImage(((isset($array['products_image_tile']) && $array['products_image_tile'] != '') ? $array['products_image_tile'] : $array['products_image']), $image);
			}
		else
			$img = '';

		require_once(DIR_FS_INC.'inc.date_short.php');
		
		$products_data = array('PRODUCTS_NAME' => (($site_params['p_name'] == 1)?htmlentities($array['products_name'], ENT_COMPAT,charset_mapper($_SESSION['language_charset'])):''),
								'COUNT' => $count,
								'COL_CLASS' => $col_class,
								'COL_SPECIAL' => $col_special_class,
								'PRODUCTS_ID' => $array['products_id'],
								'PRODUCTS_VPE' => $vpe,
								'EXTRA_DIV' => $extra_div,
								'PRODUCTS_IMAGE' => $img,
								'PRODUCTS_IMAGE_TILE' => $img_tile,
								'PRODUCTS_IMAGE_DIMENSION' => get_img_size($this->productImage($array['products_image'], $image), $max_img_size),
								'PRODUCTS_IMAGE_ALT' => ($array['products_img_alt']!=''?$array['products_img_alt']:htmlentities($array['products_name'], ENT_COMPAT,charset_mapper($_SESSION['language_charset']))),
								'PRODUCTS_LINK' => href_link(FILENAME_PRODUCT_INFO, 'products_id='.$array['products_id']),
								'PRODUCTS_MOUSE_OVER' => (($array['products_list_overlay'] == 1 && $site_params['col'] > 0 && $array['products_image']!='') ? ' title="p_overlay:includes/javascript/helper/ajax_products_tooltip.php?pID='.$array['products_id'].'"' : ''),
								'PRODUCTS_QTY' => $array['products_quantity'],
								'PRODUCTS_PRICE' => $product_price,
								'PRODUCTS_BRAND_IMG' => $brand_image,
								'PRODUCTS_BRAND_DIMENSION' => $brand_dimension,
								'PRODUCTS_BRAND_URL' => $brand_url,
								'PRODUCTS_BRAND_NAME' => $brand_name,
								'PRODUCTS_BRAND_DESC' => $brand_desc,
								'PRODUCTS_MODEL' => $model,
								'PRODUCTS_ISBN' => $isbn,
								'PRODUCTS_REVIEWS' => $reviews_img,
								'PRODUCTS_STOCK_IMG' => $stock_img,
								'PRODUCTS_TAX_INFO' => $main->getTaxInfo($tax_rate),
								'PRODUCTS_SHIPPING_LINK' => $main->getShippingLink(),
								'PRODUCTS_BUTTON_BUY_NOW' => (($site_params['b_order']==1)?$buy_now:''),
								'PRODUCTS_BUTTON_WISHLIST' => (($site_params['b_wishlist']==1)?$wishlist:''),
								'PRODUCTS_BUTTON_DETAILS' => $button_details,
								'PRODUCTS_SHIPPING_NAME'=>$shipping_status_name,
								'PRODUCTS_SHIPPING_IMAGE'=>$shipping_status_image,
								'PRODUCTS_EXPIRES' => $array['expires_date'],
								'PRODUCTS_DATE' => date_short($array['products_date_available']),
								'PRODUCTS_DESCRIPTION' => $description,
								'PRODUCTS_FSK18' => $array['products_fsk18']);
							
		return $products_data;
	}

	function productImage($name, $type) {
		$path_no = DIR_WS_IMAGES;
		
		switch ($type) {
			case 'icon':
				$path = DIR_WS_ICON_IMAGES;
				break;
				
			case 'info':
				$path = DIR_WS_INFO_IMAGES;
				break;
				
			case 'thumbnail':
				$path = DIR_WS_THUMBNAIL_IMAGES;
				break;
				
			case 'popup':
				$path = DIR_WS_POPUP_IMAGES;
				break;
		}

		if($name == '') {
			if ($this->useStandardImage == 'true' && $this->standardImage != '')
				return $path_no.$this->standardImage.$type.'.jpg';
		} else {
			if (!file_exists($path.$name)) {
				if ($this->useStandardImage == 'true' && $this->standardImage != '')
					return $path_no.$this->standardImage.$type.'.jpg';
			}
			return $path.$name;
		}
	}
	
	function getMenuID($name) {
		global $db;
		$id = $db->db_query("SELECT
									parent_id
								FROM
									".TABLE_ADMIN_MENU."
								WHERE
									menu_name = '".$name."'", true);
		if($id->_numOfRows)
			return 'menu='.$id->fields['parent_id'];
	}
	
	function getKonfiguratorOptions() {
		global $db;
		$query = $db->db_query("
			SELECT
				konfigurator_option_group, konfigurator_option 
			FROM
				".TABLE_KONFIGURATOR_PRODUCT_OPTION." AS t
			where
				t.product_id = '".$this->pID."'
				and konfigurator_option <> 'HAVE_TO'", true);

		$data = array();
		while(!$query->EOF) {
			if(!isset($data[$query->fields['konfigurator_option_group']]))
				$data[$query->fields['konfigurator_option_group']] = array();

			$data[$query->fields['konfigurator_option_group']] 
				= array_merge($data[$query->fields['konfigurator_option_group']], explode(',', $query->fields['konfigurator_option']));
			$query->MoveNext();
		}

		return $data;
	}
	
}?>